package com.example.j202411.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import com.example.j202411.R;
import com.qweather.sdk.bean.geo.GeoBean;

import java.util.List;

public class CityAdapter extends ArrayAdapter<GeoBean.LocationBean> {

    private Context context;
    private List<GeoBean.LocationBean> cityList;

    public CityAdapter(Context context, List<GeoBean.LocationBean> cityList) {
        super(context, 0, cityList);
        this.context = context;
        this.cityList = cityList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_city, parent, false);
        }

        GeoBean.LocationBean city = cityList.get(position);

        TextView cityNameTextView = convertView.findViewById(R.id.city_name);

        cityNameTextView.setText(city.getName());

        return convertView;
    }
}